#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct EDGE {
    int src;
    int dest;
    int id;
    EDGE() { src = 0, dest = 0, id = 0; }
    EDGE(int s, int d, int i) { src = s, dest = d, id = i; }
};

const int MAXN = 1e5 + 10;
int n, m;
vector<vector<EDGE>> G(MAXN, vector<EDGE>(0));

bool search(const int u, const int father, const int find, vector<int> &path) {
    for (auto &edge : G[u]) {
        if (edge.dest == father) continue;
        if (edge.dest == find) {
            // cout << "find\n";
            path.push_back(edge.id);
            return true;
        }
        if (search(edge.dest, u, find, path)) {
            path.push_back(edge.id);
            return true;
        }
    }
    return false;
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n - 1; i++) {
        int f, t;
        cin >> f >> t;
        G[f].push_back(EDGE(f, t, i));
        G[t].push_back(EDGE(t, f, i));
    }

    vector<int> ans(0);
    for (int i = 1; i <= m; i++) {
        vector<int> path(0);
        int f, t;
        cin >> f >> t;
        search(f, 0, t, path);
        if (ans.empty())
            for (auto &it : path) ans.push_back(it);
        else {
            vector<int> temp(0);
            for (auto &it : path) {
                auto loc = find(ans.begin(), ans.end(), it);
                if (loc != ans.end()) temp.push_back(it);
            }
            ans = temp;
        }
        if (ans.empty()) {
            cout << -1 << endl;
            return 0;
        }
    }
    sort(ans.begin(), ans.end());
    cout << *(ans.end() - 1);
}